package com.zzl.admin.entity.admin;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zzl.admin.entity.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Table;
import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * Description：角色实体类
 * Created by 朱正磊 on 2019-03-22 0:54
 */
@Entity(name = "tb_role")
@Data
@EqualsAndHashCode(callSuper = false)
@Table(appliesTo = "tb_role", comment = "角色表")
public class Role extends BaseEntity {

    private static final long serialVersionUID = -3325738425924411930L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "int(11) comment '角色id'")
    private Integer id;

    @Column(columnDefinition = "varchar(255) comment '角色名称'")
    private String name;

    @Column(columnDefinition = "varchar(255) comment '角色key'")
    private String roleKey;

    @Column(columnDefinition = "int(11) comment '角色状态：0-正常；1-删除'")
    private Integer status;

    @Column(columnDefinition = "varchar(255) comment '角色描述'")
    private String description;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(columnDefinition = "datetime comment '创建时间'")
    private Date createTime;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(columnDefinition = "datetime comment '更新时间'")
    private Date updateTime;

    @ManyToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.LAZY)
    @JoinTable(name = "tb_role_resource", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "resource_id") })
    private Set<Resource> resources;

}
